﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Buyer
{
    public partial class wfComments : msBsc.Cls.BPUser
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void BindInfo()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.Alert("参数错误");
                return;
            }
            string productid = this.GetParamHtValue("prid");
            if (string.IsNullOrEmpty(productid))
            {
                this.Alert("参数错误");
                return;
            }
            //获取车辆订单 信息 bind
            using (msBsc.AppLogic.DataAlc.CBizOrdersInfo orderInfo = new AppLogic.DataAlc.CBizOrdersInfo())
            {
                DataTable dt = orderInfo.GetOrdersInfoByID(orderId, productid);
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 100, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp_order').html();
                            laytpl(_html).render(" + ret + @", function (render) {
                                $('#detailInfo').html(render);
                                $('#svc_list_temp_order').remove();
                            });bindOrderInfo('" + dt.Rows[0]["ORDER_STATUS"].ToString() + "');");
            }

        }

        //添加评论
        public void AddComments()
        {
            string Comments = this.GetParamHtValue("Comments");
            if (string.IsNullOrEmpty(Comments))
            {
                this.ExecJScript(@"layer.alert('评论内容不能为空.', 3);");return;
            }
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.ExecJScript(@"layer.alert('参数错误.', 3);");return;
            }

            string productId = this.GetParamHtValue("paroductId");
            if (string.IsNullOrEmpty(productId))
            {
                this.ExecJScript(@"layer.alert('参数错误.', 3);");return;
            }

            string[] images = { };
            string imgs = this.GetParamHtValue("imgUrls");
            if (!string.IsNullOrEmpty(imgs))
            {
                images = imgs.Split('$');
                if (images.Length > 5)
                {
                    this.ExecJScript(@"layer.alert('评论图片数量不能超过5个.', 3);"); return;
                }
            }

            //添加评论信息
            using (msBsc.AppLogic.DataAlc.CBizCustomerEvlution CBEComments = new AppLogic.DataAlc.CBizCustomerEvlution())
            {
                string ms = CBEComments.AddCustomerEvlution(orderId, productId, Comments, images);
                if (ms != "OK")
                {
                    this.ExecJScript(@"layer.alert('" + ms + "', 3);");
                }
                else
                {
                    this.ExecJScript(@"success();");
                }
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "BindInfo")
            {
                BindInfo();
            }
            else if (this.strAction == "addComments")
            {
                AddComments();
            }
        }
    }
}